package bh;

import java.util.Scanner;

public class A2 {
    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        double a = in.nextDouble();
        double b = in.nextDouble();
        double c = in.nextDouble();
        double d = in.nextDouble();
        double y;
        if (a>12 && b<13){
            if(c>4||d<20){
                y= 3*a+10*b+5*d-c;
            }else {
                y=10*d-(a+b)*c/5;
            }
        }else {
            y=Math.pow(a,c)+Math.pow(b,d);
        }
        System.out.println(y);
    }
}
